#!/bin/sh
# This regression test is a part of SIPp.
# The BYE of an aborted call starts a transaction of its own: its branch
# is not that of the ACK sent before it.
. "`dirname "$0"`/../functions"; init

sippfg -sf uas.xml -i 127.0.0.1 -p 27350 -m 1 -timeout 4 -timeout_error \
    -trace_msg -message_file uas.log >/dev/null 2>&1 &
uas=$!
sleep 1
sippfg -sf uac.xml -i 127.0.0.1 -p 27351 -m 1 127.0.0.1:27350 \
    -timeout 4 >/dev/null 2>&1
wait $uas
status=$?
branch() {
    sed -n "/^$1 /,/^\$/s/^Via:.*branch=\([^;[:space:]]*\).*/\1/p" uas.log
}
ack=`branch ACK`
bye=`branch BYE`
rm -f uas.log

if test $status -ne 0; then
    fail "the UAS got no BYE ($status)"
elif test -z "$ack" || test "$ack" = "$bye"; then
    fail "the BYE has the branch of the ACK: \"$bye\""
else
    ok
fi
